package com.filldream.fastboot.web.controller.pc;


import com.filldream.fastboot.base.entity.MallCategory;
import com.filldream.fastboot.base.request.IdSTO;
import com.filldream.fastboot.base.request.pc.mallCategory.AddMallCategorySTO;
import com.filldream.fastboot.base.request.pc.mallCategory.MallCategoryListSTO;
import com.filldream.fastboot.base.request.pc.mallCategory.ModifyMallCategorySTO;
import com.filldream.fastboot.base.request.pc.mallCategory.MoveCategorySTO;
import com.filldream.fastboot.common.entity.B;
import com.filldream.fastboot.common.entity.R;
import com.filldream.fastboot.common.util.TransferUtil;
import com.filldream.fastboot.core.manager.MallCategoryManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(tags = "PC-商品分类")
@RestController
@RequestMapping("/pc/mallCategory")
public class PcMallCategoryController {

    @Autowired
    private MallCategoryManager mallCategoryManager;

    @ApiOperation(value = "商品分类列表")
    @PostMapping("/list")
    public R<List<MallCategory>> list(@RequestBody MallCategoryListSTO mallCategoryListSTO ){
        return mallCategoryManager.list(mallCategoryListSTO);
    }

    @ApiOperation(value = "商品分类详情")
    @PostMapping("/get")
    public R<MallCategory> get(@RequestBody IdSTO idSTO ){
        return R.autoSuccess( mallCategoryManager.getById(idSTO.getId()) );
    }

    @ApiOperation(value = "添加商品分类")
    @PostMapping("/add")
    public R<MallCategory> add(@RequestBody @Valid AddMallCategorySTO addMallCategory ){
        MallCategory mallCategory = TransferUtil.changeToObj(addMallCategory, MallCategory.class);
        return mallCategoryManager.add(mallCategory);
    }

    @ApiOperation(value = "修改商品分类")
    @PostMapping("/modify")
    public B modify(@RequestBody @Valid ModifyMallCategorySTO addMallCategory ){
        MallCategory mallCategory = TransferUtil.changeToObj(addMallCategory, MallCategory.class);
        return mallCategoryManager.modify(mallCategory);
    }

    @ApiOperation(value = "移动商品分类")
    @PostMapping("/move")
    public B move(@RequestBody @Valid MoveCategorySTO moveCategorySTO ){
        return mallCategoryManager.move(moveCategorySTO);
    }

    @ApiOperation(value = "删除商品分类",notes = "传入分类ID")
    @PostMapping("/del")
    public B del(@RequestBody IdSTO idSTO ){
        return mallCategoryManager.del(idSTO.getId());
    }

}
